<!--
 * @author  dumeng
-->
<template>
  <div class="platform-auto-login" />
</template>

<script>
export default {
  name: 'PlatformAutoLogin',
  created() {
    if (this.$route.query.key) {
      this.autoLogin()
    } else {
      this.$router.replace('/login')
    }
  },
  methods: {
    autoLogin() {
      const loading = this.$loading({
        lock: true,
        text: '自动登录中，请稍后',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.1)'
      })
      this.$store.dispatch('LoginByKey', this.$route.query.key).then(() => {
        loading.close()
        localStorage.setItem('isLogin', 1)
        this.$router.replace({ path: '/' })
      }).catch(() => {
        loading.close()
        this.$router.replace('/login')
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
